Car类
class Car(val licensePlate: String, val brand: String, val color: String, val price: Double) {
  private var fuel = 0.0

  def drive(distance: Double): Unit = {
    println(s"Driving $brand for $distance miles.")
  }

  def park(): Unit = {
    println(s"Parking $brand (license plate: $licensePlate).")
  }

  def refuel(amount: Double): Unit = {
    fuel += amount
    println(s"Refueled $amount gallons. Current fuel level: $fuel gallons.")
  }
}

// ElectricCar子类
class ElectricCar(licensePlate: String, brand: String, color: String, price: Double, val batteryCapacity: Double, var remainingRange: Double) extends Car(licensePlate, brand, color, price) {

  def charge(amount: Double): Unit = {
    val newRange = remainingRange + amount * batteryCapacity
    remainingRange = if (newRange > batteryCapacity) batteryCapacity else newRange
    println(s"Charged $amount kWh. Remaining range: $remainingRange miles.")
  }

  override def drive(distance: Double): Unit = {
    if (distance > remainingRange) {
      println(s"Cannot drive $distance miles. Remaining range is only $remainingRange miles.")
    } else {
      remainingRange -= distance
      super.drive(distance)
      println(s"Remaining range: $remainingRange miles.")
    }
  }
}
